package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.request.IResponse;

/**
 * Created by gjw on 2017/3/27.
 */

public class ModifyChannelValues extends BaseCommand {
    private final int index, action, value;

    /**
     * @param index
     * @param action //0为恢复默认值，1为覆盖默认值，2为叠加至默认值
     * @param value
     */
    public ModifyChannelValues(int index, int action, int value) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_SET_CH_SETTING);
        if (action < 0 || action > 2) {
            throw new IllegalArgumentException("错误的操作类型");
        }
        this.index = index;
        this.action = action;
        this.value = value;

    }

    @Override
    protected short[] body() {
        short[] body = new short[4];
        body[0] = (short) index;
        body[1] = (short) action;
        shortToUIntArray(body, 2, (short) value);
        return body;
    }

    @Override
    public IResponse toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        return new IResponse(ids(), code);
    }

}
